package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.LedgerOrderService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.LedgerOrderDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/ledgerOrder")
public class LedgerOrderController extends BaseController {
    @Resource
    private LedgerOrderService ledgerOrderService;
    @Resource
    private UserService userService;

    @PostMapping("/list")
    public ServerResponse list(HttpServletRequest request, @RequestBody LedgerOrderDto ledgerOrderDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        ledgerOrderDto.setUserInfo(userInfo);
        ledgerOrderDto.setPageNum(Integer.parseInt(request.getParameter("pageNum")));
        ledgerOrderDto.setPageSize(Integer.parseInt(request.getParameter("pageSize")));
        return ServerResponse.createBySuccess(ledgerOrderService.findLedgerOrderList(ledgerOrderDto));
    }
    @PostMapping("/findStat")
    public ServerResponse findStat(@RequestBody LedgerOrderDto ledgerOrderDto, HttpServletRequest request) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        ledgerOrderDto.setUserInfo(userInfo);
        return ledgerOrderService.findStat(ledgerOrderDto);
    }
}
